import heapq
from typing import List


class Solution:
    def scheduleCourse(self, sticks: List[int]) -> int:
        heapq.heapify(sticks)
        total_cost = 0
        while len(sticks) > 1:
            a = heapq.heappop(sticks)
            b = heapq.heappop(sticks)
            cur = a + b
            total_cost += cur
            heapq.heappush(sticks, cur)
        return sticks[0] + total_cost